
package com.joysuch.wwyt.core.enums;

/**
 * 业务代码模型
 *
 * @author zhangxiaohuan
 * @company huanke
 * @date 2019年11月22日 下午7:53:13
 * @since
 */
public enum RiskLevels {

    ZHONG_DA_FENG_XIAN(1, "重大风险", "红"),
    JIAO_DA_FENG_XIAN(2, "较大风险", "橙"),
    YI_BAN_FENG_XIAN(3, "一般风险", "黄"),
    DI_FENG_XIAN(4, "低风险", "蓝"),
    FEI_ZHONG_DA(0, "非重大", "浅蓝"),
    ;

    int code;
    String name;
    String riskColor;

    private RiskLevels(int code, String name, String riskColor) {
        this.code = code;
        this.name = name;
        this.riskColor = riskColor;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRiskColor() {
        return riskColor;
    }

    public void setRiskColor(String riskColor) {
        this.riskColor = riskColor;
    }

    public static RiskLevels valueOf(int code) {
        RiskLevels[] values = RiskLevels.values();
        for (RiskLevels r : values) {
            if (r.code == code) {
                return r;
            }
        }
        return null;
    }

    public static RiskLevels findByName(String name) {
        RiskLevels[] values = RiskLevels.values();
        for (RiskLevels r : values) {
            if (r.name.equals(name)) {
                return r;
            }
        }
        return null;
    }

    public static String findRiskLevelName(Integer code) {
        if (code == null) {
            return null;
        }
        RiskLevels of = valueOf(code);
        return of == null ? null : of.name;
    }

    public static String findRiskColorByCode(Integer code) {
        if (code == null) {
            return null;
        }
        RiskLevels riskLevels = valueOf(code);
        return riskLevels == null ? null : riskLevels.riskColor;
    }

    public static String findRiskNameByCode(Integer code) {
        if (code == null) {
            return null;
        }
        RiskLevels riskLevels = valueOf(code);
        return riskLevels == null ? null : riskLevels.name;
    }

    public static Integer getRealLevelIntValue(Double realLevel) {
        if (realLevel==null){
            return null;
        }
        Integer level = realLevel.intValue();
        if (realLevel != null) {
            if (realLevel > 4) {
                level = 4;
            } else if (realLevel < 1) {
                level = 1;
            }
        }
        return level;
    }

    public static String getRealLevelIntValueName(Double realLevel) {
        Integer value = getRealLevelIntValue(realLevel);
        return findRiskLevelName(value);
    }
}
